package servlet;

import dao.Function;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/timecheck")
public class TimeCheckServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Function insert = new Function();
        String y_m_d = req.getParameter("y_m_d");
        String start_time = y_m_d + req.getParameter("start_time")+":00";
        String end_time = y_m_d + req.getParameter("end_time")+":00";
        String seat_name = req.getParameter("seat_name");
        String person_id = req.getParameter("person_id");
////        String time_submit = req.getParameter("time_submit");
//            insert.choose(start_time,end_time,seat_name,person_id);
//        //resp.sendRedirect("SeatServlet");

        String success = "预约成功，请及时签到.";
        String fault = "预约时间冲突!";
        boolean a = insert.choose(start_time,end_time,seat_name,person_id);
        if (a){
            req.setAttribute("s_or_f",success);
        }else {
            req.setAttribute("s_or_f",fault);
        }
            req.getRequestDispatcher("SeatServlet").forward(req,resp);
            System.out.println("已执行choose函数");
    }
//        private Integer time_to_number (String time){
//            if(time != null){
//                return Integer.parseInt(time.substring(3))+Integer.parseInt(time.substring(0,2))*60;
//            }else {return null;}
//        }

}
